package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cnzz.site1255174697.R;
import com.cnzz.site1255174697.model.BaseEntity;
import com.cqyanyu.yanyu.view.XBaseViewHolder;

import java.util.List;

/**
 * 分类名列表
 */
public class KindsListAdapter extends BaseAdapter {

    private Context context;
    private List<BaseEntity> list;
    private int select = -1;

    public KindsListAdapter(Context context, List<BaseEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public BaseEntity getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_kinds_name, null);
        }
        TextView tvTitle = XBaseViewHolder.get(convertView, R.id.tv_title);
        View check = XBaseViewHolder.get(convertView, R.id.check);

        BaseEntity kindsEntity = list.get(position);
        tvTitle.setText(kindsEntity.getName());

        if (select == 0) {
            check.setVisibility(View.VISIBLE);
            convertView.setBackgroundResource(R.color.white);
        }
        if (select == position) {
            check.setVisibility(View.VISIBLE);
            convertView.setBackgroundResource(R.color.white);
        } else {
            check.setVisibility(View.GONE);
            convertView.setBackgroundResource(R.color.bg_color);
        }
        return convertView;
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
        notifyDataSetChanged();
    }
}
